package com.zxp.springcloud.services.impl;

import com.zxp.springcloud.services.ImessageProvider;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.MessageBuilder;

import javax.annotation.Resource;
import java.util.UUID;

/**
 * @description:
 * @author: 张新朋
 * @time: 2020/5/8 11:20
 */
@EnableBinding(Source.class)
public class MessageProviderImpl implements ImessageProvider {
    @Resource
    private MessageChannel output;

    @Override
    public String send() {
        String serial = UUID.randomUUID().toString();
        boolean send = output.send(MessageBuilder.withPayload(serial).build());
        if(send){
            System.out.println("消息发送------"+serial);
            return "成功------";
        }else{
            System.out.println("失败------");
            return "失败------";
        }
    }
}